home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / include / x11 / xlocalei.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-11  |  10.9 KB  |  314 lines

  1. /*
  2.  * $XConsortium: Xlocaleint.h,v 1.35 92/04/14 15:55:37 rws Exp $
  3.  */
  4.  
  5. /*
  6.  * Copyright 1990, 1991 by OMRON Corporation, NTT Software Corporation,
  7.  *                      and Nippon Telegraph and Telephone Corporation
  8.  * Copyright 1991 by the Massachusetts Institute of Technology
  9.  *
  10.  * Permission to use, copy, modify, distribute, and sell this software and its
  11.  * documentation for any purpose is hereby granted without fee, provided that
  12.  * the above copyright notice appear in all copies and that both that
  13.  * copyright notice and this permission notice appear in supporting
  14.  * documentation, and that the names of OMRON, NTT Software, NTT, and M.I.T.
  15.  * not be used in advertising or publicity pertaining to distribution of the
  16.  * software without specific, written prior permission. OMRON, NTT Software,
  17.  * NTT, and M.I.T. make no representations about the suitability of this
  18.  * software for any purpose.  It is provided "as is" without express or
  19.  * implied warranty.
  20.  *
  21.  * OMRON, NTT SOFTWARE, NTT, AND M.I.T. DISCLAIM ALL WARRANTIES WITH REGARD
  22.  * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  23.  * AND FITNESS, IN NO EVENT SHALL OMRON, NTT SOFTWARE, NTT, OR M.I.T. BE
  24.  * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 
  25.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  26.  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  27.  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  28.  * 
  29.  *    Authors: Li Yuhong        OMRON Corporation
  30.  *         Tatsuya Kato        NTT Software Corporation
  31.  *         Hiroashi Kuribayashi    OMRON Corporation
  32.  *   
  33.  */
  34.  
  35. /*
  36.  *      Xlocaleint.h -- Header definition.
  37.  * 
  38.  */
  39. #ifndef _XLOCALEINT_H_
  40. #define _XLOCALEINT_H_
  41.  
  42. #define _WCHARXLIB_
  43. #include "wcharint.h"
  44. #undef _WCHARXLIB_
  45.  
  46. #include <X11/Xlocale.h>
  47. #include "Xlcint.h"
  48.  
  49. #define MAXCHARSETS         16
  50. #define MAXSEQUENCELENGTH   255
  51.  
  52. #define XDEFAULT_STATE 0xffffff  /* to specify default _State for XConvertXXToXX */
  53. /*
  54.  * Charset id of codeset. Maximun is 10 charsets of one codeset.
  55.  * Must Define:  CODESETi = i, other functions will use this convension.
  56.  * 
  57.  */
  58. typedef    unsigned int _State;
  59. typedef    unsigned char _CSID;
  60.  
  61. #define CODESET0     0   /* Charset 0 */
  62. #define CODESET1     1   /* Charset 1 */
  63. #define CODESET2     2   /* Charset 2 */
  64. #define CODESET3     3   /* Charset 3 */
  65. #define CODESET4     4   /* Charset 4 */
  66. #define CODESET5     5   /* Charset 5 */
  67. #define CODESET6     6   /* Charset 6 */
  68. #define CODESET7     7   /* Charset 7 */
  69. #define CODESET8     8   /* Charset 8 */
  70. #define CODESET9     9   /* Charset 9 */
  71. #define CODESETA     10   /* Charset A */
  72. #define CODESETB     11   /* Charset B */
  73. #define CODESETC     12   /* Charset C */
  74. #define CODESETD     13   /* Charset D */
  75. #define CODESETE     14   /* Charset E */
  76. #define CODESETF     15   /* Charset F */
  77. #define C0      16  /* Control Set 0 */
  78. #define C1      17  /* Control Set 1 */
  79. #define ND      127 /* Not Defined */
  80.  
  81. /* ISO encoding */
  82. #define    GL    0
  83. #define    GR    0x80
  84. #define    C94    0
  85. #define    C96    1
  86.  
  87. /*
  88.  * Type of codeset
  89.  */
  90. #define CDS_STATELESS   1   /* state-independent codeset */
  91. #define CDS_STATEFUL    2   /* state-dependent codeset */
  92. #define CDS_SELFDEFINED 10  /* self defined codeset, not used yet.*/
  93.  
  94.  
  95. /*
  96.  * Data Structure for Convert Map List
  97. */
  98. typedef struct {
  99.     unsigned int  mb_start;    /* starting code point of multibyte*/
  100.     unsigned int  mb_end;      /* ending code point of multibyte  */
  101.     unsigned int  cs_start;    /* starting code point of charset */
  102.     unsigned int  cs_end;      /* ending code point of charset  */
  103. } Range;
  104.  
  105. /*
  106.  * Data Structure for Codeset
  107.  */
  108. typedef struct {                    /* Stateless Codeset */
  109.     int     cds_type;               /* stateless type */
  110.     _CSID   cds_num;                /* number of charsets */
  111.     _State  mb_init;            /* inital designate */
  112.     int     cds_msbon;              /* 8bit encoding or not */
  113.     int     cds_mb_cur_max;        /* max number of bytes of this codeset */
  114.                     /* = max(cds_mblen) + max(cds_dsg) */
  115.     int     cds_mblen[MAXCHARSETS]; /* mb length of each charsets */
  116.     unsigned short cs_offset[MAXCHARSETS]; /* GL or GR */
  117.     Range  *cds_cnvlist;            /* table-driven conversion list */
  118.     int     cds_cnvindex[MAXCHARSETS];/* conversion list index */
  119.     int   (*cds_cnvproc)();         /* procedure-driven conversion, not used */
  120.     union {
  121.         _CSID  map[256];         /* charset mapping table,stateless CCS*/
  122.         char *dsg[MAXCHARSETS]; /* designation of charaset,stateful CCS*/
  123.    } cds;
  124. #define cds_map  cds.map
  125. #define cds_dsg  cds.dsg
  126. } Codeset; 
  127.  
  128. /*
  129.  * The number of charasets is different from the number of fonts in
  130.  * some codeset, e.g., the current UJIS, no extended font for CODESET3.
  131.  */
  132. typedef struct {
  133.     char           *cs_name;    /* charset name: CharSetReg-CharSetEncoding */
  134.     wchar           cs_woff;    /* wchar offset of DP 10646 */
  135.     int             cs_len;     /* length in bytes */
  136.     char           *cs_des;     /* designate sequence of COMPOUND TEXT */
  137.     _CSID        cs_GLorGR;
  138.     _CSID        cs_id;    /* index of ISOStateTable(_XInitCTEncoding) */
  139. }               Charset;
  140.  
  141. typedef struct {
  142.     int       fs_num;           /* number of fonts of locale */
  143.     Charset **fs_cset;          /* charset encoding */
  144. } Fontset;
  145.  
  146. typedef struct _XLocaleDB {
  147.     char          *lc_name;        /* locale name for LC_ALL */
  148.     char          *lc_encoding;    /* encoding name */
  149.     Codeset          *lc_codeset;    /* category of codeset */
  150.     Fontset          *lc_fontset;    /* category of fontset */
  151.     struct _XLocaleDB *next;        /* chain pointer */
  152. } XLocaleDB;
  153.  
  154. /* the definition for initial state of locale is:
  155.  
  156.     initial state of state-independent codeset:
  157.      byte 2         byte 1         byte 0
  158.    +-------------+--------------+--------------+
  159.    | GL/GR flag  |  CODESET0    |  CODESET0    |
  160.    +-------------+--------------+--------------+
  161.  
  162.     initial state of state-dependent codeset:
  163.       byte 2         byte 1         byte 0
  164.     +-------------+--------------+--------------+
  165.     | GL/GR flag  | GR CODESETj  | GL CODESETi  |
  166.     +-------------+--------------+--------------+
  167.  
  168.      where:
  169.     GL CODESETi is the first GL encoding of codeset, usually is
  170.     CODESET0.
  171.     GR CODESETj is the first GR encoding of codeset.
  172.  */
  173.  
  174. typedef struct {
  175.     XLocaleDB           *xlc_db;
  176.     char           *lc_lang;        /* locale name */
  177.     _State        ct_state;
  178.     _State        mb_state;
  179. } XLocaleRec, *XLocale;
  180.  
  181. typedef struct {
  182.     XLCdMethods        methods;        /* methods of this LC */
  183.     XLCdCoreRec        core;            /* core data of this LC */
  184.     XLocale        xlc;
  185. } XsiLCdRec, *XsiLCd;
  186.  
  187. /* 
  188.  * Data Structure for Charset.
  189.  * This charset is designated by escape sequence that is defined in ISO 2022.
  190.  */
  191. typedef struct {
  192.     int             code_bytes;     /* number of bytes of 94/96 charset*/
  193.     unsigned char   code_min,       /* minimun of all bytes of GL/GR charset */ 
  194.                     code_max;       /* maximun of all bytes of GL/GR charset */
  195. } ISOStateInfo;
  196.  
  197. /*
  198.  * Must define:
  199.  *   Success  = 0
  200.  *   BadName < 0
  201.  * Some functions will use this convension, e.g., _XwcDecomposeGlyphCharset().
  202.  */
  203. #define BufferOverFlow  (-1)
  204. #define BadBuffer       (-1)
  205. #define BadTerminate    (-2)
  206. #define BadEncoding     (-3)
  207.  
  208. #define _XctDefaultState()    (_State)(CODESET0 | CODESET1 << 8 | GL << 16)
  209. #define _XmbDefaultState(xlocale) ((xlocale)->xlc_db->lc_codeset->mb_init)
  210.  
  211. #define _Xmbtype(xlocale)    ((xlocale)->xlc_db->lc_codeset->cds_type)
  212.  
  213. #define _Xmbcsnum(xlocale)    ((xlocale)->xlc_db->lc_codeset->cds_num)
  214. #define _Xmbfsnum(xlocale)    ((xlocale)->xlc_db->lc_fontset->fs_num)
  215.  
  216.  
  217. #define ctGetGLid(xlocale)    (_CSID)((xlocale)->ct_state & 0xff)
  218. #define ctGetGRid(xlocale)    (_CSID)((xlocale)->ct_state >> 8 & 0xff)
  219. #define ctGetGLorGR(xlocale)    (_CSID)((xlocale)->ct_state >> 16 & 0xff)
  220. #define ctGetid(xlocale)    (_CSID)((ctGetGLorGR(xlocale) == GL) ? \
  221.                  ctGetGLid(xlocale) : ctGetGRid(xlocale))
  222. #define ctSetGLid(xlocale, id)    ((xlocale)->ct_state = (xlocale)->ct_state & 0xffff00 | (id))
  223. #define ctSetGRid(xlocale, id)    ((xlocale)->ct_state = \
  224.                  (xlocale)->ct_state & 0xff00ff | (_State)(id) << 8)
  225. #define ctSetGLorGR(xlocale, id) ((xlocale)->ct_state = \
  226.                  (xlocale)->ct_state & 0x00ffff | (_State)(id) << 16)
  227. #define ctSetid(xlocale, id)    ((xlocale)->ct_state = \
  228.                  (ctGetGLorGR(xlocale) == GL) ? \
  229.                  ctSetGLid(xlocale, id) : ctSetGRid(xlocale, id))
  230.  
  231. #define mbGetGLid(xlocale)    (_CSID)((xlocale)->mb_state & 0xff)
  232. #define mbGetGRid(xlocale)    (_CSID)((xlocale)->mb_state >> 8 & 0xff)
  233. #define mbGetGLorGR(xlocale)    (_CSID)((xlocale)->mb_state >> 16 & 0xff)
  234. #define mbGetid(xlocale)    (_CSID)((mbGetGLorGR(xlocale) == GL) ? \
  235.                  mbGetGLid(xlocale) : mbGetGRid(xlocale))
  236. #define mbSetGLid(xlocale, id)    ((xlocale)->mb_state = (xlocale)->mb_state & 0xffff00 | (id))
  237. #define mbSetGRid(xlocale, id)    ((xlocale)->mb_state = \
  238.                  (xlocale)->mb_state & 0xff00ff | ((_State)(id) << 8))
  239. #define mbSetGLorGR(xlocale, id) ((xlocale)->mb_state = \
  240.                  (xlocale)->mb_state & 0x00ffff | (_State)(id) << 16)
  241. #define mbSetid(xlocale, id)    ((xlocale)->mb_state = \
  242.                  (mbGetGLorGR(xlocale) == GL) ? \
  243.                  mbSetGLid(xlocale, id) : mbSetGRid(xlocale, id))
  244.  
  245. #define _Xctinit(xlocale)    ((xlocale)->ct_state = _XctDefaultState())
  246. #define _Xmbinit(xlocale)    ((xlocale)->mb_state = _XmbDefaultState(xlocale))
  247.  
  248. #define _XlcFreeLocale(xlc) Xfree((char *)(xlc))
  249.  
  250. #ifdef notdef /* I am not yet convinced we need these inside Xlib */
  251.  
  252. #ifndef X_NOT_STDC_ENV
  253. #include <limits.h>
  254. #endif
  255. #ifndef MB_LEN_MAX
  256. #define MB_LEN_MAX 6
  257. #endif
  258.  
  259. #ifndef X_NOT_STDC_ENV
  260. #include <stdlib.h>
  261. #endif
  262. #ifndef MB_CUR_MAX
  263. #define MB_CUR_MAX (_XFallBackConvert()->xlc_db->lc_codeset->cds_mb_cur_max)
  264. #endif
  265.  
  266. #endif
  267.  
  268. #define _isXString(c) \
  269.    (((c) >= 0x20 && (c) <= 0x7e) || (c) >= 0xa0 || (c) == 0x09 || (c) == 0x0a)
  270.  
  271. /* XlcAccess.c */
  272. extern int              _Xmbmsbon();
  273. extern _CSID        _Xmbcsid();
  274. extern int              _Xmblen();
  275. extern char *           _Xmbdsg();
  276. extern int              _Xmbdlen();
  277. extern Charset *        _Xmbfscs();
  278. extern char *           _Xmbfsname();
  279. extern int              _Xmbfslen();
  280. extern char *           _Xmbfsdsg();
  281. extern wchar            _Xmbfswf();
  282. extern int              _Xmbctocsc();
  283. extern int              _Xcsctombc();
  284. extern _CSID        _XmbctGLorGR();
  285. extern _CSID        _Xmbctid();
  286. extern _CSID        _Xmbctidtocsid();
  287. extern void        _XmbGetDefaultEncoding();
  288.  
  289. /* XInitCT.c */
  290. extern void             _XInitCTEncoding();
  291.  
  292. extern Bool             _XctisGLdsg();
  293. extern Bool             _XcwNameGetAll();
  294. extern _CSID        _XcwNameGetGLorGRId();
  295. extern void             _XcwGetAll();
  296. extern void        _XcwGetDefaultEncoding();
  297. extern _CSID        _XcwGetWoffsetFromLocale();
  298. extern Bool             _XcwCheckDefaultState();
  299. extern Bool        _XmbCheck();
  300. extern Bool        _XcwIdCheck();
  301. extern Bool        _XcwIdGetAll();
  302. extern Bool        _XcwIdGetEncoding();
  303. extern int        _XcwGetLength();
  304.  
  305. /* XlcLoad.c */
  306. extern XLocale        _XlcDupLocale();
  307. extern XLocale        _XlcMakeLocale();
  308. extern XLocale        _XFallBackConvert();
  309.  
  310. extern int        _XmbDecomposeGlyphCharset();
  311. extern int        _XwcDecomposeGlyphCharset();
  312.  
  313. #endif /* _XLOCALEINT_H_ */
  314.